package com.chenl.provider.DTO.enums;



public enum ExceptionCodeEnum {

    ITEM_NAME_EXIST("bitsun.ic.100001", "当前版本商品名称已存在"),
    ITEM_PARENT_CATEGORY_NOT_LEAF("bitsun.ic.100002", "类目非叶子节点无法创建商品"),;


    ExceptionCodeEnum(String code, String msg) {
        this.code = "exception_"+code;
        this.msg = msg;
    }

    private String code;
    private String msg;

    public RuntimeException exception() {
        return new RuntimeException(code+"_"+msg);
    }

    public RuntimeException exception(String record) {
        if (record == null) {
            return exception();
        }
        return new RuntimeException(code+"_"+msg);
    }

    public void checkThrow(boolean flag) {
        if (flag) throw exception();
    }

    public void checkThrow(boolean flag,String record) {
        if (flag) throw exception(record);
    }

}

